
{% extends 'base.html' %}

{% block css%}
<style type="text/css">

</style>
{% endblock %}

{% block body%} 
<div class="row">

	<div class="col-md-8">
	<h3> I2C Port Read/Write</h3>
	<table id="t_dac" class="table table-hover table-condensed form-inline">
		<tr>
			<th>Port</th>
			<th>Register</th>
			<th>Value</th>

			<th>Read</th>
			<th>Write</th>
		</tr>		
		
		{% for port in ports %}
			<tr>
				<td style="font-size:12px">
					{{ port[0] }}
				</td>

				<td>
					<input class="form-control" style="width:120px;"  value="0x0" type="text" id="i2c_port_reg_{{ port[0] }}">
				</td>

				<td>
					<input class="form-control" style="width:120px;"  type="text" id="i2c_port_val_{{ port[0] }}">
				</td>

				<td>
					<button class="btn btn-success" onClick="btn_i2c_port_get('{{ port[0] }}')">
					Read
					</button>
				</td>

				<td>
					<button class="btn btn-primary" onClick="btn_i2c_port_set('{{ port[0] }}')">
					Write
					</button>
				</td>
			</tr>
			{% endfor %}
	</table>
	</div>

</div>
{% endblock %}

{% block js%} 
{{ super() }}
<script type="text/javascript">

	function btn_i2c_port_get(item)
	{
		$.post("api/btn_i2c_port_get",
        {
            port:item,
            reg:$("#i2c_port_reg_" + item).val(),
            // val:$("#i2c_port_val_" + item).val(),
        },
        function(data,status){
            console.log("data: " + data);
			// cells = data.split(",");
			$("#i2c_port_val_" + item).val(data);

        });
	}


	function btn_i2c_port_set(item)
	{
		reg = $("#i2c_port_reg_" + item).val();
		val = $("#i2c_port_val_" + item).val();

		console.log(item);
		console.log(reg);
		console.log(val);
		$.post("api/btn_i2c_port_set",
        {
			port:item,
			reg:reg,
			val:val,
        },
        function(data,status){
        	toastr["success"]("Command successfully issued.");
            console.log("data: " + data);
        });
	}


	$(document).ready(function(){
        toastr.options = {
            "closeButton": true,
            "positionClass": "toast-top-center"
        } 
         
		// $("#btn_get_all_loading").hide();
		// read_session_data();


		// get all --new method
		// $('#btn_get_all').click(function(){
		// 	btn_get_all();
		// });


	});
</script>
{% endblock %}